#define BLINKER_WIFI
 
#include <Blinker.h>
#include <DHT.h>
 
char auth[] = "774c60aac10f"; //上一步中在app中获取到的Secret Key（新建设备的秘钥）

char ssid[] = "ZFQ"; //你的WiFi热点名称

char pswd[] = "123456789"; //你的WiFi密码
 
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
 
#define DHTPIN 2
 
#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
 
DHT dht(DHTPIN, DHTTYPE);
 
float humi_read = 0, temp_read = 0;
 
void heartbeat()
{
    //反馈温度数据
    HUMI.print(humi_read);
    //设置ui组件图标和颜色
    HUMI.icon("fas fa-thermometer-2");
    HUMI.color("#fddb10");

    //反馈湿度数据
    TEMP.print(temp_read);
    TEMP.icon("fas fa-heart");
    HUMI.color("#fddb01");
}
 
void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);
    BLINKER_DEBUG.debugAll();
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
 
    Blinker.begin(auth, ssid, pswd);
    Blinker.attachHeartbeat(heartbeat);
    dht.begin();
}
 
void loop()
{
    Blinker.run();
 
    float h = dht.readHumidity();
    float t = dht.readTemperature();
 
    if (isnan(h) || isnan(t))
    {
        BLINKER_LOG("Failed to read from DHT sensor!");
    }
    else
    {
        BLINKER_LOG("Humidity: ", h, " %");
        BLINKER_LOG("Temperature: ", t, " *C");
        humi_read = h;
        temp_read = t;
    }
 
    Blinker.delay(2000);
}